/*
 * Powered By [rapid-framework]
 * Web Site: http://www.rapid-framework.org.cn
 * Google Code: http://code.google.com/p/rapid-framework/
 * Since 2008 - 2013
 */
package com.lims.admin.model;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.*;

import org.hibernate.annotations.GenericGenerator;

import org.hibernate.validator.constraints.*;
import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

import com.lims.landInfo.model.Corpaff;

import javacommon.base.*;

/**
 * @author badqiu email:badqiu(a)gmail.com
 * @version 1.0
 * @since 1.0
 */

@Entity
@Table(name = "T_USER")
public class User extends BaseEntity implements java.io.Serializable {
	private static final long serialVersionUID = 5454155825314635342L;

	// alias
	public static final String TABLE_ALIAS = "用户";
	public static final String ALIAS_OBJID = "ID";
	public static final String ALIAS_USERNO = "用户编号";
	public static final String ALIAS_USER_NAME = "用户";
	public static final String ALIAS_PASSWORD = "密码";
	public static final String ALIAS_USER_REAL_NAME = "真实姓名";

	// date formats

	// 可以直接使用: @Length(max=50,message="用户名长度不能大于50")显示错误消息
	// columns START
	/**
	 * objid db_column: OBJID
	 */
	@Length(max = 32)
	private java.lang.String objid;
	/**
	 * userno db_column: userno
	 */
	@Length(max = 50)
	private java.lang.String userno;
	/**
	 * userName db_column: userName
	 */
	@Length(max = 50)
	private java.lang.String userName;
	/**
	 * password db_column: password
	 */
	@Length(max = 50)
	private java.lang.String password;
	/**
	 * userRealName db_column: userRealName
	 */
	@Length(max = 50)
	private java.lang.String userRealName;
	private String corpId;  //---corpAff ID
	private List<Menu> menus = new ArrayList<Menu>(0);
	private Corpaff corp;
	//用户单位及所有下属单位的编号
	private List<String> corpnoList = new ArrayList<String>(0);
	// columns END

	public User() {
	}
	
	public User(java.lang.String objid) {
		this.objid = objid;
	}

	public void setObjid(java.lang.String value) {
		this.objid = value;
	}
	

	@Id
	@GeneratedValue(generator = "custom-id")
	@GenericGenerator(name = "custom-id", strategy = "uuid")
	@Column(name = "OBJID", nullable = false, insertable = true, updatable = true, length = 32)
	public java.lang.String getObjid() {
		return this.objid;
	}

	@Column(name = "userno", unique = false, nullable = true, insertable = true, updatable = true, length = 50)
	public java.lang.String getUserno() {
		return this.userno;
	}

	public void setUserno(java.lang.String value) {
		this.userno = value;
	}

	@Column(name = "userName", unique = false, nullable = true, insertable = true, updatable = true, length = 50)
	public java.lang.String getUserName() {
		return this.userName;
	}

	public void setUserName(java.lang.String value) {
		this.userName = value;
	}

	@Column(name = "password", unique = false, nullable = true, insertable = true, updatable = true, length = 50)
	public java.lang.String getPassword() {
		return this.password;
	}

	public void setPassword(java.lang.String value) {
		this.password = value;
	}

	@Column(name = "userRealName", unique = false, nullable = true, insertable = true, updatable = true, length = 50)
	public java.lang.String getUserRealName() {
		return this.userRealName;
	}

	public void setUserRealName(java.lang.String value) {
		this.userRealName = value;
	}

	private List<Role> roles = new ArrayList<Role>(0);
	
	@ManyToMany
	@JoinTable(name="t_user_role_mapping",
			joinColumns={@JoinColumn(name="userId")},
			inverseJoinColumns={@JoinColumn(name="roleId")})
	public List<Role> getRoles() {
		return roles;
	}

	public void setRoles(List<Role> roles) {
		this.roles = roles;
	}
	
	@Column(name = "corpId", unique = false, nullable = true, insertable = true, updatable = true, length = 32)
	public String getCorpId() {
		return corpId;
	}

	public void setCorpId(String corpId) {
		this.corpId = corpId;
	}
	
	@ManyToOne
	@JoinColumn(name="corpId",insertable=false,updatable=false)
	public Corpaff getCorp() {
		return corp;
	}

	public void setCorp(Corpaff corp) {
		this.corp = corp;
	}

	public String toString() {
		return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
				.append("Objid", getObjid()).append("Userno", getUserno())
				.append("UserName", getUserName()).append("Password",
						getPassword())
				.append("UserRealName", getUserRealName()).toString();
	}

	public int hashCode() {
		return new HashCodeBuilder().append(getObjid()).toHashCode();
	}
	
	@Transient
	public List<Menu> getMenus() {
		return menus;
	}

	public void setMenus(List<Menu> menus) {
		this.menus = menus;
	}
	@Transient
	public List<String> getCorpnoList() {
		return corpnoList;
	}

	public void setCorpnoList(List<String> corpnoList) {
		this.corpnoList = corpnoList;
	}

	public boolean equals(Object obj) {
		if (obj instanceof User == false)
			return false;
		if (this == obj)
			return true;
		User other = (User) obj;
		return new EqualsBuilder().append(getObjid(), other.getObjid())
				.isEquals();
	}
	
}
